package com.jo.advisor;

import com.jo.util.ReflectionUtils;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;

/**
 * 抽象advice，提供一些advice的公共方法
 * @author Jo
 * @date 2018/1/25
 */
@Slf4j
public abstract class AbstractAdvice implements Advice {

    /**
     * advice注解标注的方法
     */
    private Method adviceMethod;

    /**
     * aspectj注解的类的实例
     */
    private Object aspectObj;

    public AbstractAdvice(Method adviceMethod, Object aspectObj) {
        this.adviceMethod = adviceMethod;
        this.aspectObj = aspectObj;
    }

    protected void invokeAdviceMethod(){
        log.info("开始调用advice方法");
        ReflectionUtils.methodInvoke(this.adviceMethod, new Object[]{}, this.aspectObj);
    }
}
